package kr.hkit.androidcomplete02.ch12;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewResource extends Activity {
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_listviewarraylist);

		final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
				R.array.country, android.R.layout.simple_list_item_1);
		
		ListView listview = (ListView) findViewById(R.id.ch12_listView);
		listview.setAdapter(adapter);
		
		listview.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Log.d("ListViewResource", "position : " + position + ", id : " + id);
				String text = "Select Item = " + adapter.getItem(position);
				Toast.makeText(getApplication(), text, Toast.LENGTH_SHORT).show();
			}
		});
	}
}
